package src.Skills;

import src.Main;
import src.Players.*;
import src.NPCs.*;

public class Thieving
{
    private int thiefXPRate = 1;
    private Player p;
    private int[] farmerItems = {995,5318};
    private int[] farmerItemAmts = {9,1};
    private int[] HAMItems = {688,686,697,314,882,1351,1205,1265,1739,1349,1267,1059,1061,1511,1734,321,2138,440,453,886,
    1353,1269,946,1733,1207,590,1627,1625,4310,4306,4304,4298,4300,4306,4302,995};
    private int[] HAMItemAmts = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
    private int[] rogueItems = {995,995,1523,1219,1993,556};
    private int[] rogueItemAmts = {25,40,1,1,1,8};
    private int[] masterFarmerItems = {5096,5097,5098,5099,5100,5280,5281,5282,5291,5292,5293,5294,5295,5296,5297,5298,
    5299,5300,5301,5302,5303,5304,5305,5306,5307,5308,5309,5310,5311,5312,5313,5314,5315,5316,5317,5318,5319,5320,5321,
    5322,5323,5324};
    private int[] masterFarmerItemAmts = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
    ,1,1,1};
    private int[] watchmanItems = {995,2309};
    private int[] watchmanItemAmts = {60,1};
    private int[] paladinItems = {995,562};
    private int[] paladinItemAmts = {80,2};
    private int[] gnomeItems = {995,557,2150,444,569,2162};
    private int[] gnomeItemAmts = {300,1,1,1,1,1};
    private int[] heroItems = {995,995,565,1601,1991,560,569,444};
    private int[] heroItemAmts = {200,300,1,1,1,2,1,1};

    public Thieving(Player _p)
    {
        p = _p;
    }

    public void thieveNPC(int npcId)
    {
        if(p == null || npcId < 0 || npcId > Main.m.ge.maxNPCs || Main.m.ge.npcs[npcId] == null)
        {
            return;
        }
        if(p.canWalkDelay > 0)
        {
            return;
        }
        int slot = 0;
        NPC n = Main.m.ge.npcs[npcId];
        int thiefLvl = p.skillLvl[17];
        PlayerItems pi = new PlayerItems();
        switch(n.npcType)
        {
            case 1: //Man.
            case 2: //Man.
            case 3: //Man.
            case 4: //Woman.
            case 5: //Woman.
            case 6: //Woman.
                if(thiefLvl < 1)
                {
                    p.frame.sendMessage(p, "You need at least 1 Thieving to pickpocket a " + Main.m.ge.getNPCName(n.npcType));
                    break;
                }
                else if(random(thiefLvl + 1) >= 1)
                {
                    p.frame.sendMessage(p, "You manage to pick the " + Main.m.ge.getNPCName(n.npcType) + "'s pocket.");
                    pi.addItem(p, 995, 3);
                    p.requestAnim(881, 5);
                    p.addSkillXP(8 * thiefXPRate, 17);
                }
                else
                {
                    p.frame.sendMessage(p, "The " + Main.m.ge.getNPCName(n.npcType) + " catches you!");
                    n.requestText("Robber! Robber!");
                    n.requestAnim(NPCAttack.getMeleeAttackAnimation(n), 5);
                    n.requestFaceCoords(p.absX, p.absY);
                    p.canWalkDelay = 12;
                    p.requestGFX(80, 6553600);
                    p.appendHit(random(n.maxHit), 0);
                }
            break;
            case 7: //Farmer.
                if(thiefLvl < 10)
                {
                    p.frame.sendMessage(p, "You need at least 10 Thieving to pickpocket a " + Main.m.ge.getNPCName(n.npcType));
                    break;
                }
                else if(random(thiefLvl) >= 5)
                {
                    p.frame.sendMessage(p, "You manage to pick the " + Main.m.ge.getNPCName(n.npcType) + "'s pocket.");
                    slot = random(farmerItems.length);
                    pi.addItem(p, farmerItems[slot], farmerItemAmts[slot]);
                    p.requestAnim(881, 5);
                    p.addSkillXP(14 * thiefXPRate, 17);
                }
                else
                {
                    p.frame.sendMessage(p, "The " + Main.m.ge.getNPCName(n.npcType) + " catches you!");
                    n.requestText("Robber! Robber!");
                    n.requestAnim(NPCAttack.getMeleeAttackAnimation(n), 5);
                    n.requestFaceCoords(p.absX, p.absY);
                    p.canWalkDelay = 12;
                    p.requestGFX(80, 6553600);
                    p.appendHit(random(n.maxHit), 0);
                }
            break;
            case 1714: //Male H.A.M. member.
            case 1715: //female H.A.M. member.
                if(npcId == 1714 && thiefLvl < 20)
                {
                    p.frame.sendMessage(p, "You need at least 20 Thieving to pickpocket a " + Main.m.ge.getNPCName(n.npcType));
                    break;
                }
                else if(npcId == 1715 && thiefLvl < 15)
                {
                    p.frame.sendMessage(p, "You need at least 15 Thieving to pickpocket a " + Main.m.ge.getNPCName(n.npcType));
                    break;
                }
                else if(npcId == 1714 && random(thiefLvl) >= 10 || npcId == 1715 && random(thiefLvl) >= 7)
                {
                    p.frame.sendMessage(p, "You manage to pick the " + Main.m.ge.getNPCName(n.npcType) + "'s pocket.");
                    slot = random(HAMItems.length);
                    pi.addItem(p, HAMItems[slot], HAMItemAmts[slot]);
                    p.requestAnim(881, 5);
                    if(npcId == 1714)
                    {
                        p.addSkillXP(22 * thiefXPRate, 17);
                    }
                    else if(npcId == 1715)
                    {
                        p.addSkillXP(18 * thiefXPRate, 17);
                    }
                }
                else
                {
                    p.frame.sendMessage(p, "The " + Main.m.ge.getNPCName(n.npcType) + " catches you!");
                    n.requestText("Robber! Robber!");
                    n.requestAnim(NPCAttack.getMeleeAttackAnimation(n), 5);
                    n.requestFaceCoords(p.absX, p.absY);
                    p.canWalkDelay = 12;
                    p.requestGFX(80, 6553600);
                    p.appendHit(random(n.maxHit), 0);
                }
            break;
            case 15: //Warrior.
                if(thiefLvl < 25)
                {
                    p.frame.sendMessage(p, "You need at least 25 Thieving to pickpocket a " + Main.m.ge.getNPCName(n.npcType));
                    break;
                }
                else if(random(thiefLvl) >= 12)
                {
                    p.frame.sendMessage(p, "You manage to pick the " + Main.m.ge.getNPCName(n.npcType) + "'s pocket.");
                    pi.addItem(p, 995, 18);
                    p.requestAnim(881, 5);
                    p.addSkillXP(26 * thiefXPRate, 17);
                }
                else
                {
                    p.frame.sendMessage(p, "The " + Main.m.ge.getNPCName(n.npcType) + " catches you!");
                    n.requestText("Robber! Robber!");
                    n.requestAnim(NPCAttack.getMeleeAttackAnimation(n), 5);
                    n.requestFaceCoords(p.absX, p.absY);
                    p.canWalkDelay = 12;
                    p.requestGFX(80, 6553600);
                    p.appendHit(random(n.maxHit), 0);
                }
            break;
            case 187: //Rogue.
                if(thiefLvl < 32)
                {
                    p.frame.sendMessage(p, "You need at least 32 Thieving to pickpocket a " + Main.m.ge.getNPCName(n.npcType));
                    break;
                }
                else if(random(thiefLvl) >= 16)
                {
                    p.frame.sendMessage(p, "You manage to pick the " + Main.m.ge.getNPCName(n.npcType) + "'s pocket.");
                    slot = random(rogueItems.length);
                    pi.addItem(p, rogueItems[slot], rogueItemAmts[slot]);
                    p.requestAnim(881, 5);
                    p.addSkillXP(36 * thiefXPRate, 17);
                }
                else
                {
                    p.frame.sendMessage(p, "The " + Main.m.ge.getNPCName(n.npcType) + " catches you!");
                    n.requestText("Robber! Robber!");
                    n.requestAnim(NPCAttack.getMeleeAttackAnimation(n), 5);
                    n.requestFaceCoords(p.absX, p.absY);
                    p.canWalkDelay = 12;
                    p.requestGFX(80, 6553600);
                    p.appendHit(random(n.maxHit), 0);
                }
            break;
            case 2234: //Master farmer.
            case 2235: //Master farmer.
                if(thiefLvl < 38)
                {
                    p.frame.sendMessage(p, "You need at least 38 Thieving to pickpocket a " + Main.m.ge.getNPCName(n.npcType));
                    break;
                }
                else if(random(thiefLvl) >= 19)
                {
                    p.frame.sendMessage(p, "You manage to pick the " + Main.m.ge.getNPCName(n.npcType) + "'s pocket.");
                    slot = random(masterFarmerItems.length);
                    pi.addItem(p, masterFarmerItems[slot], masterFarmerItemAmts[slot]);
                    p.requestAnim(881, 5);
                    p.addSkillXP(43 * thiefXPRate, 17);
                }
                else
                {
                    p.frame.sendMessage(p, "The " + Main.m.ge.getNPCName(n.npcType) + " catches you!");
                    n.requestText("Robber! Robber!");
                    n.requestAnim(NPCAttack.getMeleeAttackAnimation(n), 5);
                    n.requestFaceCoords(p.absX, p.absY);
                    p.canWalkDelay = 12;
                    p.requestGFX(80, 6553600);
                    p.appendHit(random(n.maxHit), 0);
                }
            break;
            case 9: //Guard.
            case 10: //Guard.
            case 32: //Guard.
                if(thiefLvl < 40)
                {
                    p.frame.sendMessage(p, "You need at least 40 Thieving to pickpocket a " + Main.m.ge.getNPCName(n.npcType));
                    break;
                }
                else if(random(thiefLvl) >= 20)
                {
                    p.frame.sendMessage(p, "You manage to pick the " + Main.m.ge.getNPCName(n.npcType) + "'s pocket.");
                    pi.addItem(p, 995, 30);
                    p.requestAnim(881, 5);
                    p.addSkillXP(46 * thiefXPRate, 17);
                }
                else
                {
                    p.frame.sendMessage(p, "The " + Main.m.ge.getNPCName(n.npcType) + " catches you!");
                    n.requestText("Stop thief!");
                    n.requestAnim(NPCAttack.getMeleeAttackAnimation(n), 5);
                    n.requestFaceCoords(p.absX, p.absY);
                    p.canWalkDelay = 12;
                    p.requestGFX(80, 6553600);
                    p.appendHit(random(n.maxHit), 0);
                }
            break;
            case 1305: //Fremennik.
                if(thiefLvl < 45)
                {
                    p.frame.sendMessage(p, "You need at least 45 Thieving to pickpocket a " + Main.m.ge.getNPCName(n.npcType));
                    break;
                }
                else if(random(thiefLvl) >= 23)
                {
                    p.frame.sendMessage(p, "You manage to pick the " + Main.m.ge.getNPCName(n.npcType) + "'s pocket.");
                    pi.addItem(p, 995, 40);
                    p.requestAnim(881, 5);
                    p.addSkillXP(65 * thiefXPRate, 17);
                }
                else
                {
                    p.frame.sendMessage(p, "The " + Main.m.ge.getNPCName(n.npcType) + " catches you!");
                    n.requestText("Robber! Robber!");
                    n.requestAnim(NPCAttack.getMeleeAttackAnimation(n), 5);
                    n.requestFaceCoords(p.absX, p.absY);
                    p.canWalkDelay = 12;
                    p.requestGFX(80, 6553600);
                    p.appendHit(random(n.maxHit), 0);
                }
            break;
            case 23: //Knight.
            case 26: //Knight.
                if(thiefLvl < 55)
                {
                    p.frame.sendMessage(p, "You need at least 55 Thieving to pickpocket a " + Main.m.ge.getNPCName(n.npcType));
                    break;
                }
                else if(random(thiefLvl) >= 27)
                {
                    p.frame.sendMessage(p, "You manage to pick the " + Main.m.ge.getNPCName(n.npcType) + "'s pocket.");
                    pi.addItem(p, 995, 50);
                    p.requestAnim(881, 5);
                    p.addSkillXP(84 * thiefXPRate, 17);
                }
                else
                {
                    p.frame.sendMessage(p, "The " + Main.m.ge.getNPCName(n.npcType) + " catches you!");
                    n.requestText("Stop thief!");
                    n.requestAnim(NPCAttack.getMeleeAttackAnimation(n), 5);
                    n.requestFaceCoords(p.absX, p.absY);
                    p.canWalkDelay = 12;
                    p.requestGFX(80, 6553600);
                    p.appendHit(random(n.maxHit), 0);
                }
            break;
            case 34: //Watchman.
                if(thiefLvl < 65)
                {
                    p.frame.sendMessage(p, "You need at least 65 Thieving to pickpocket a " + Main.m.ge.getNPCName(n.npcType));
                    break;
                }
                else if(random(thiefLvl) >= 33)
                {
                    p.frame.sendMessage(p, "You manage to pick the " + Main.m.ge.getNPCName(n.npcType) + "'s pocket.");
                    slot = random(watchmanItems.length);
                    pi.addItem(p, watchmanItems[slot], watchmanItemAmts[slot]);
                    p.requestAnim(881, 5);
                    p.addSkillXP(137 * thiefXPRate, 17);
                }
                else
                {
                    p.frame.sendMessage(p, "The " + Main.m.ge.getNPCName(n.npcType) + " catches you!");
                    n.requestText("Stop thief!");
                    n.requestAnim(NPCAttack.getMeleeAttackAnimation(n), 5);
                    n.requestFaceCoords(p.absX, p.absY);
                    p.canWalkDelay = 12;
                    p.requestGFX(80, 6553600);
                    p.appendHit(random(n.maxHit), 0);
                }
            break;
            case 1904: //Menaphite Thug.
            case 1905: //Menaphite Thug.
                if(thiefLvl < 65)
                {
                    p.frame.sendMessage(p, "You need at least 65 Thieving to pickpocket a " + Main.m.ge.getNPCName(n.npcType));
                    break;
                }
                else if(random(thiefLvl) >= 33)
                {
                    p.frame.sendMessage(p, "You manage to pick the " + Main.m.ge.getNPCName(n.npcType) + "'s pocket.");
                    pi.addItem(p, 995, 60);
                    p.requestAnim(881, 5);
                    p.addSkillXP(137 * thiefXPRate, 17);
                }
                else
                {
                    p.frame.sendMessage(p, "The " + Main.m.ge.getNPCName(n.npcType) + " catches you!");
                    n.requestText("Stop thief!");
                    n.requestAnim(NPCAttack.getMeleeAttackAnimation(n), 5);
                    n.requestFaceCoords(p.absX, p.absY);
                    p.canWalkDelay = 12;
                    p.requestGFX(80, 6553600);
                    p.appendHit(random(n.maxHit), 0);
                }
            break;
            case 20: //Paladin.
                if(thiefLvl < 70)
                {
                    p.frame.sendMessage(p, "You need at least 70 Thieving to pickpocket a " + Main.m.ge.getNPCName(n.npcType));
                    break;
                }
                else if(random(thiefLvl) >= 35)
                {
                    p.frame.sendMessage(p, "You manage to pick the " + Main.m.ge.getNPCName(n.npcType) + "'s pocket.");
                    slot = random(paladinItems.length);
                    pi.addItem(p, paladinItems[slot], paladinItemAmts[slot]);
                    p.requestAnim(881, 5);
                    p.addSkillXP(151 * thiefXPRate, 17);
                }
                else
                {
                    p.frame.sendMessage(p, "The " + Main.m.ge.getNPCName(n.npcType) + " catches you!");
                    n.requestText("Stop thief!");
                    n.requestAnim(NPCAttack.getMeleeAttackAnimation(n), 5);
                    n.requestFaceCoords(p.absX, p.absY);
                    p.canWalkDelay = 12;
                    p.requestGFX(80, 6553600);
                    p.appendHit(random(n.maxHit), 0);
                }
            break;
            case 67: //Gnome.
            case 68: //Gnome.
            case 69: //Gnome.
                if(thiefLvl < 75)
                {
                    p.frame.sendMessage(p, "You need at least 75 Thieving to pickpocket a " + Main.m.ge.getNPCName(n.npcType));
                    break;
                }
                else if(random(thiefLvl) >= 38)
                {
                    p.frame.sendMessage(p, "You manage to pick the " + Main.m.ge.getNPCName(n.npcType) + "'s pocket.");
                    slot = random(gnomeItems.length);
                    pi.addItem(p, gnomeItems[slot], gnomeItemAmts[slot]);
                    p.requestAnim(881, 5);
                    p.addSkillXP(198 * thiefXPRate, 17);
                }
                else
                {
                    p.frame.sendMessage(p, "The " + Main.m.ge.getNPCName(n.npcType) + " catches you!");
                    n.requestText("Robber! Robber!");
                    n.requestAnim(NPCAttack.getMeleeAttackAnimation(n), 5);
                    n.requestFaceCoords(p.absX, p.absY);
                    p.canWalkDelay = 12;
                    p.requestGFX(80, 6553600);
                    p.appendHit(random(n.maxHit), 0);
                }
            break;
            case 21: //Hero.
                if(thiefLvl < 80)
                {
                    p.frame.sendMessage(p, "You need at least 80 Thieving to pickpocket a " + Main.m.ge.getNPCName(n.npcType));
                    break;
                }
                else if(random(thiefLvl) >= 40)
                {
                    p.frame.sendMessage(p, "You manage to pick the " + Main.m.ge.getNPCName(n.npcType) + "'s pocket.");
                    slot = random(heroItems.length);
                    pi.addItem(p, heroItems[slot], heroItemAmts[slot]);
                    p.requestAnim(881, 5);
                    p.addSkillXP(273 * thiefXPRate, 17);
                }
                else
                {
                    p.frame.sendMessage(p, "The " + Main.m.ge.getNPCName(n.npcType) + " catches you!");
                    n.requestText("Stop thief!");
                    n.requestAnim(NPCAttack.getMeleeAttackAnimation(n), 5);
                    n.requestFaceCoords(p.absX, p.absY);
                    p.canWalkDelay = 12;
                    p.requestGFX(80, 6553600);
                    p.appendHit(random(n.maxHit), 0);
                }
            break;
            default:
                Main.m.log("[" + p.playerIndex + "-" + p.username + "] Unable to thieve NPC " + n.npcType);
            break;
        }
        pi = null;
    }

    private int random(int range)
    {
        return (int)(Math.random() * range);
    }
}